<template>
  <view class="loginContainer">
    <image
      class="logo"
      src="https://i.niupic.com/images/2022/02/11/9UHr.jpg"
    ></image>
    <form>
      <input type="text" v-model="userinfo.form.mobile" placeholder="请输入手机号" />
      <input type="text" value="" placeholder="请输入密码" />
    </form>
    <button @click="toLogin" type="primary">登 录</button>
    <text>没有账号? 新用户填写信息立即注册</text>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {
        form: {
          smsCode: "1234",
          mobile: "",
          isParty: false,
          partyData: {},
        }, // 用户信息对象
      },
    };
  },
  methods: {
    //登录跳转路由
    toPersonal() {
			uni.reLaunch({
			  url: "/pages/personal/personal",
			});
    },
    //发起登录请求
    async toLogin() {
			const {form} = this.userinfo
			if(form.mobile == null ||form.mobile == "" ){
				uni.showToast({
					icon:'error',
					title:'请输入手机号'
				})
				return false
			}
      const result = await uni.request({
        url: "https://yoshop.zyf520.xyz/index.php?s=/api/passport/login",
        data: {
					...(this.userinfo)
        },
				header: {
				  platform: "H5",
				},
        method: "POST",
        success: (res) => {
          uni.setStorageSync("token", res.data.data.token);
					if(res.data.status === 200){
						this.toPersonal()
					}else{
						uni.showToast({
							icon:'error',
							title:res.data.message
						})
					}
        },
        fail: (err) => {
          console.log(err.message);
        },
      });
    },
  },
};
</script>

<style lang="stylus">
.loginContainer {
  width: 100%;
  height: 100%;
  background: #fff;
  display: flex;
  align-items: center;
  flex-direction: column;

  .logo {
    width: 400upx;
    height: 370upx;
    margin-top: 100upx;
    margin-bottom: 70upx;
  }

  input {
    width: 650upx;
    height: 80upx;
    margin-bottom: 35upx;
    border: none;
    border-bottom: #ececec solid 1upx;
    font-size: 30upx;
    color: black;
  }

  button {
    width: 700upx;
    height: 80upx;
    line-height: 80upx;
    background-color: #fe5c2d;
    font-weight: 400;
    font-size: 30upx;
    color: #fff;
    border-radius: 50upx;
    margin-top: 60upx;
  }

  text {
    margin-top: 30upx;
    color: #ababab;
    font-size: 24upx;
    text-align: center;
  }
}
</style>
